﻿using ICSharpCode.SharpZipLib.Zip;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace SimpleNugetServer
{
    public static class ZipInputStreamExtensions
    {
        public static string ReadString(this ZipInputStream stream, ZipEntry entry)
        {
            var buffer = new byte[8096];
            using (var ms = new MemoryStream())
            {
                while (true)
                {
                    var count = stream.Read(buffer, 0, buffer.Length);
                    if (count == 0) break;

                    ms.Write(buffer, 0, count);
                }

                ms.Position = 0;
                using (var reader = new StreamReader(ms))
                {
                    return reader.ReadToEnd();
                }
            }
        }
    }
}
